package com.joker.aigc.oj.service.impl.codesandbox;

import com.joker.aigc.oj.service.CodeSandbox;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author Antares
 * @date 2023/9/3 8:24
 * @description 代码沙箱工厂（根据字符串参数创建指定的代码沙箱实例）
 */
@Component
public class CodeSandboxFactory {


    @Resource
    private RemoteCodeSandbox remoteCodeSandbox;
    @Resource
    private ThirdPartyCodeSandbox thirdPartyCodeSandbox;
    @Resource
    private ExampleCodeSandbox exampleCodeSandbox;
    @Resource
    private NativeCodeSandbox nativeCodeSandbox;



    /**
     * 创建代码沙箱示例
     *
     * @param type 沙箱类型
     * @return
     */
    public CodeSandbox newInstance(String type) {
        System.out.println("创建了CodeSandbox");
        /**
         * 创建 沙箱
         */
        CodeSandbox codeSandbox;
        switch (type) {
            case "docker" :
                codeSandbox=nativeCodeSandbox;
                break;
            case "native" :
                codeSandbox=nativeCodeSandbox;
                break;
            case "remote" :
                codeSandbox=remoteCodeSandbox;
                break;
            case "thirdParty" :
                codeSandbox=thirdPartyCodeSandbox;
                break;
            default : codeSandbox=exampleCodeSandbox;break;
        };
        return codeSandbox;
    }
}
